package com.mike.employment.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mike.employment.base.ApiResult;
import com.mike.employment.base.PageRequest;
import com.mike.employment.po.Notice;
import com.mike.employment.service.NoticeService;

@RestController
@RequestMapping("/api/notice")
public class NoticeController {
	
	@Autowired
	private NoticeService noticeService;
	
	@PostMapping("/page")
	public ApiResult page(@RequestBody PageRequest req) {
		return ApiResult.success(noticeService.getPage(req));
	}

	@PutMapping()
	public ApiResult saveOrUpdate(@RequestBody Notice notice) {
		return ApiResult.success(noticeService.saveOrUpdate(notice));
	}
	
	@DeleteMapping()
	public ApiResult delete(@RequestBody Long ...ids) {
		return ApiResult.success(noticeService.delete(ids));
	}
	
	@GetMapping("/{id}")
	public ApiResult findNotice(@PathVariable("id") Long id) {
		return ApiResult.success(noticeService.findById(id));
	}
}
